﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CC98;
using CC98.Data;
using CC98.Network;
using CC98.Network.Primitives;

namespace CC98.UserSession
{
    /// <summary>
    /// This session class store the current user session state
    /// Tracking authentication state
    /// Store operation history
    /// etc.
    /// </summary>
    public class UserSessionInstance
    {
        internal UserSessionInstance(CC98Client client)
        {
            client.AuthenticationStateChanged += ClientAuthenticationStateChanged;
        }

        public User User
        {
            get
            {
                return this.Client.User;
            }
        }

        public CC98Client Client { get; private set; }

        public event EventHandler<AuthenticationStateChangedEventArgs> AuthenticationStateChanged; 

        protected virtual void OnAuthenticationStateChanged(bool? isAuthenticated)
        {
            var eventHandler = this.AuthenticationStateChanged;
            if (eventHandler != null)
                eventHandler(this, new AuthenticationStateChangedEventArgs(isAuthenticated));
        }

        private void ClientAuthenticationStateChanged(object sender, AuthenticationStateChangedEventArgs e)
        {
            this.OnAuthenticationStateChanged(e.IsAuthenticated);
        }
    }
}
